package mapper.Practice;

import com.bdqn.sj.pojo.SysRole;
import com.bdqn.sj.pojo.SysUser;
import com.bdqn.sj.service.SysUserService;
import org.apache.log4j.Logger;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.ArrayList;
import java.util.List;

public class SysUserTest {
    private Logger logger = Logger.getLogger(SysUserTest.class);


    public void testGetUserList() {
        ApplicationContext ctx = new ClassPathXmlApplicationContext("sj/applicationContext.xml");
        SysUserService userService = (SysUserService) ctx.getBean("sysUserService");

        // 调用模糊查询用户信息方法
        List<SysUser> userList = new ArrayList<SysUser>();
        SysUser sysUser = new SysUser();
        sysUser.setRealName("赵");
        sysUser.setRoleId(2);
        userList = userService.getList(sysUser);

        for (SysUser userResult : userList) {
            logger.debug("testGetUserList account: "
                    + userResult.getAccount() + " and realName: "
                    + userResult.getRealName() + " and roleId: "
                    + userResult.getRoleId() + " and roleName: "
                    + userResult.getRoleIdName() + " and address: "
                    + userResult.getAddress());
        }

    }


    @Test
    public void testGetUser(){
        ApplicationContext ctx = new ClassPathXmlApplicationContext("sj/applicationContext.xml");
        SysUserService userService = (SysUserService) ctx.getBean("sysUserService");
        // 调用查询所有用户信息方法
        List<SysUser> user = userService.getUser();
        for (SysUser sysUser: user ) {
            logger.debug("testGetUser account: "
                    + sysUser.getAccount() + " and realName: "
                    + sysUser.getRealName() + " and roleId: "
                    + sysUser.getRoleId() + " and roleName: "
                    + sysUser.getRoleIdName() + " and address: "
                    + sysUser.getAddress());
        }
    }


    @Test
    public void testAdd(){
        ApplicationContext ctx = new ClassPathXmlApplicationContext("sj/applicationContext.xml");
        SysUserService userService = (SysUserService) ctx.getBean("sysUserService");
        SysRole sysRole = new SysRole();
        sysRole.setCode("SMBMS_EMPLOYEEA");
        sysRole.setRoleName("董事长");
        sysRole.setCreatedUserId(1);
        sysRole.setCreatedTime("2019-04-13 00:00:00");
        int add = userService.add(sysRole);
        if (add > 0){
            System.out.println("角色数据添加成功！");
        }

    }

   
    @Test
    public void testDel(){
        ApplicationContext ctx = new ClassPathXmlApplicationContext("sj/applicationContext.xml");
        SysUserService userService = (SysUserService) ctx.getBean("sysUserService");
        int del = userService.del(1);
        if (del > 0){
            System.out.println("删除角色信息成功");
        }
    }




}
